class Solution:
    def numberOfGoodPartitions(self, nums) -> int:
        n = len(nums)
        base = 10 ** 9 + 7
        prefix = [0] * n
        count = [0] * n
        last_index = [-1] * n
        d = {}
        for index, num in enumerate(nums):
            if num in d:
                last_index[index] = d[num]
            d[num] = index
        for index, num in enumerate(nums):
            if index == 0:
                count[index] = 1
                prefix[index] = 1
            else:
                last = last_index[index]
                if last == -1:
                    count[index] = prefix[index - 1] + 1
                else:
                    if last == 0:
                        count[index] = prefix[index - 1]
                    else:
                        count[index] = (prefix[index - 1] - prefix[last - 1]) % base
            prefix[index] = (prefix[index - 1] + count[index]) % base
        return count[-1]

data = Solution()
nums = [1, 2, 3, 4]
print(data.numberOfGoodPartitions(nums))